	//日历
	var Calendar=function(selector,options){
		this.selector=selector;
		if(typeof options!="undefined"){
			this.options=$.extend({},this.getDefaultOptions(),options);
			this.dateStr=this.options.value;
		}else{
			this.options=$.extend({},this.getDefaultOptions());
		}
		this.dateStr=this.options.value;
		this.date=Utils.getDateByDateStr(this.dateStr);
	}
	Calendar.WEEK_DICT=["日","一","二","三","四","五","六"]
	Calendar.WEEK_DICT_CLASSNAME=["sun","mon","tues","wed","thurs","fri","sat"]
	
	Calendar.MONTH_DICT=["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]
	
	Calendar.prototype=new Control();
	Calendar.prototype.dateStr="";
	
	Calendar.options={
		startDate:"1900-1-1",
		startDateNotFitTips:"不得早于预定的起始时间",
		
		endDate:"2099-12-31",
		endDateNotFitTips:"不得晚于预定的结束时间",
		
		startSelector:"",
		startSelectorNotFitTips:"不得早于选择的起始时间",
		
		endSelector:"",
		endSelectorNotFitTips:"不得晚于选择的结束时间",
		
			
		monthInfoListUrl:"monthInfoList.do",
		setDate:function(date){
			
		}
	}
	Calendar.prototype.init=function(){
		this.year=this.date.getFullYear();
		this.month=this.date.getMonth();
		this.day=this.date.getDate();
		
		this.element=$(this.selector).get(0);
		this.element.className="ht-calendar";
		
		var content=this.element.innerHTML;
		this.element.innerHTML=""
		this.setContent(content);
		
		//this.styleElement=$("<link href=\"/common/HTMLTurbo/0.1.0/module/control/dateInput/common.css\" rel=\"stylesheet\" type=\"text/css\" />").get(0);
		
		var self=this;
		
		this.yearController=new Calendar.YearController(this.year,function(flag){self.switchYear(flag)});
		this.yearElement=this.yearController.getElement();
		
		this.monthController=new Calendar.MonthController(this.month,function(flag){self.switchMonth(flag);});
		this.monthElement=this.monthController.getElement();
		
		this.dayList=new Calendar.DayList(this.date,function(value){self.options.setDate(value)},this.infoList,this.options);
		this.dayListElement=this.dayList.getElement()
		
		//ht.update(this.dayListElement);
		
		this.weekList=new Calendar.WeekList();
		this.weekListElement=this.weekList.getElement()
		
		
		//this.element.appendChild(this.styleElement);
		this.element.appendChild(this.yearElement);
		this.element.appendChild(this.monthElement);
		this.element.appendChild(this.weekListElement);
		this.element.appendChild(this.dayListElement);
		
		this.endYear=this.options.endDate.split("-")[0]
		this.startYear=this.options.startDate.split("-")[0]
	}
	Calendar.prototype.infoList=null;
	Calendar.prototype.setContent=function(content){
		var itemList=$("li",content);
		var item=null;
		
		var infoList=new Array();
		var info={};
		
		var title="";
		var dateStr="";
		var date=null;
		var target="";
		
		for(var i=0;i<itemList.length;i++){
			item=itemList[i];
			title=$("a",item).attr("title");
			url=$("a",item).attr("href");
			dateStr=$(".dateTime",item).html();
			target=$("a",item).attr("target");
			//console.log(dateStr);
			
			date=Utils.getDateByDateStr(dateStr);//console.log(1);
			dateStr=Utils.getDateStr(date);
			
			info={
				title:title,
				url:url,
				dateStr:dateStr,
				date:date,
				target:target
			};
			infoList.push(info);
		}
		this.infoList=infoList;
		//console.log(infoList);
	};
	
	Calendar.prototype.getDefaultOptions=function(){
		var options=Calendar.options;
		
		var date=new Date();
		var dateStr=Utils.getDateStr(date)
		options.value=dateStr;
		
		return options;
	}
	Calendar.prototype.switchYear=function(flag){
		var endYear=this.endYear
		var startYear=this.startYear
		
		if(flag=="+"){
			if(endYear>this.year){
				this.year++;
			}else{
				return false;
			}
		}else{
			if(startYear<this.year){
				this.year--;
			}else{
				return false;
			}
		}
		this.update();
		return true;
	}
	Calendar.prototype.switchMonth=function(flag){
		if(flag=="+"){
			this.month++;
		}else{
			this.month--;
		}
		if(this.month==12){
			if(this.switchYear("+")){
				this.month=0;
			}else{
				this.month=11;
			}
		}
		if(this.month<0){
			if(this.switchYear("-")){
				this.month=11;
			}else{
				this.month=0;
			}
		}
		this.update();
	}
	Calendar.prototype.update=function(){
		this.yearController.setValue(this.year);
		this.monthController.setValue(this.month);
		this.dayList.setYearMonth(this.year,this.month);
	}
	Calendar.prototype.getElement=function(){
		return this.element;
	}
	
	
	
	
	
	
	//星期列表
	Calendar.WeekList=function(){
		this.init();
	}
	Calendar.WeekList.prototype.init=function(){
		this.element=document.createElement("ul");
		this.element.className="weekList";
		this.update();
	}
	Calendar.WeekList.prototype.update=function(){
		var total=7;
		var listItemArray=new Array();
		var listItem=null;
		
		for(var i=0;i<total;i++){
			listItem=new Calendar.WeekListItem(i);
			this.element.appendChild(listItem.getElement())
			listItemArray.push(listItem);
		}
	}
	Calendar.WeekList.prototype.getElement=function(){
		return this.element;
	}
	Calendar.WeekListItem=function(num){
		this.num=num;
		this.init();
	}
	Calendar.WeekListItem.prototype.init=function(){
		this.element=document.createElement("li")
		this.text=document.createElement("a")
		this.element.appendChild(this.text);
		this.update();
	}
	Calendar.WeekListItem.prototype.update=function(){
		var text=Calendar.WEEK_DICT[this.num];
		this.text.innerHTML=text;
		
		this.element.className=Calendar.WEEK_DICT_CLASSNAME[this.num]
	}
	Calendar.WeekListItem.prototype.getElement=function(){
		return this.element;
	}
	
	
	//日期列表
	Calendar.DayList=function(currentDate,setDate,infoList,options){
		this.currentDate=currentDate;
		
		this.year=this.currentDate.getFullYear();
		this.month=this.currentDate.getMonth();
		
		this.infoList=infoList;
		
		this.setDate=setDate
		
		this.options=options
		this.init();
	}
	Calendar.DayList.prototype.init=function(){
		this.element=document.createElement("ul");
		this.element.className="dayList"
		//this.update();
		
		this.setYearMonth(this.year,this.month);
	}
	Calendar.DayList.prototype.setYearMonth=function(year,month){
		this.year=year
		this.month=month;
		
		//var url="monthInfoList.json?year="+year+"&month="+month;
		//var url="monthInfoList.do?year="+year+"&month="+(month+1);
		var url=this.options.monthInfoListUrl
		url+="?year="+year+"&month="+(month+1);
		var self=this;
		var options={
			url: url,
			dataType:"json",
			cache:false,
			success: function(data, textStatus, jqXHR){
				//self.loadRuleSuccess(data);
				self.infoList=data;
				self.update();
			},
			error :function(){
				alert("rule load error ");
			}
		}
		$.ajax(options);
	}
	Calendar.DayList.prototype.update=function(){
		var self=this;
		
		var year=this.year;
		var month=this.month
		var day=0;
		
		var length=Utils.getYearMonthDayLength(year,month);
		var listItemArray=new Array();
		var listItem=null;
		
		this.element.innerHTML="";
		var listItemElement=null;
		
		var firstDate=Utils.getDate(year,month,day+1);
		var week=firstDate.getDay();
		var date=null;
		for(var i=0;i<week;i++){
			this.element.appendChild($("<li><a></a></li>").get(0));
		}
		for(var i=0;i<length;i++){
			date=Utils.getDate(this.year,this.month,i+1);
			listItem=new Calendar.DayListItem(i,date,this.currentDate,function(num){self.focusControl(num);},this.infoList);
			listItemArray.push(listItem);
			listItemElement=listItem.getElement()
			
			this.element.appendChild(listItemElement);
		}
		ht.update(this.element);
	}
	Calendar.DayList.prototype.focusControl=function(num){
		var date=Utils.getDate(this.year,this.month,num+1);
		this.setDate(date);
	}
	Calendar.DayList.prototype.getElement=function(){
		return this.element;
	}
	
	Calendar.DayListItem=function(num,date,currentDate,focusControl,infoList){
		this.num=num;
		this.focusControl=focusControl;
		this.date=date;
		this.currentDate=currentDate;
		this.infoList=infoList;
		
		this.init();
	}
	Calendar.DayListItem.prototype.getInfo=function(){
		var infoList=this.infoList;
		var info=null;
		var date=null;
		
		for(var i=0;i<infoList.length;i++){
			info=infoList[i];
			//var dateStr=Utils.getDateStr(date)
			date=Utils.getDateByDateStr(info.date);
			//console.log(date);
			//info.date=Utils.getDateByDateStr(info.date);
			//console.log(Utils.getDateStr(date));
			//console.log(Utils.getDateStr(this.date));
			//console.log(info.date==this.date);
			if(Utils.getDateStr(date)==Utils.getDateStr(this.date)){
				return info;
			}
		}
		return null;
	}
	Calendar.DayListItem.prototype.init=function(){
		this.element=document.createElement("li")
		this.aElement=document.createElement("a")
		
		this.infoElement=document.createElement("span")
		this.infoElement.className="info";
		
		var info=this.getInfo();
		//console.log(info);
		if(info!=null){
			$(this.aElement).attr("href",info.url);
			$(this.aElement).attr("title",info.title);
			$(this.aElement).attr("target",info.target);
			
			this.element.className="info"
		}
		this.element.className+=" "+Calendar.WEEK_DICT_CLASSNAME[this.date.getDay()]
		if(this.date.getTime()==this.currentDate.getTime()){
			this.element.className=this.element.className+" current"
		}
		
		this.aElement.innerHTML=this.getText();
		this.aElement.appendChild(this.infoElement);
		
		this.element.appendChild(this.aElement);
		
		var self=this;
		$(this.element).bind("click",function(event){return self.clickHandle(event)})
	}
	Calendar.DayListItem.prototype.getText=function(){
		return this.num+1;
	}
	Calendar.DayListItem.prototype.getElement=function(){
		return this.element;
	}
	Calendar.DayListItem.prototype.clickHandle=function(event){
		this.focusControl(this.num);
		return true;
	}
	
	
	
	
	
	

	Calendar.ValueController=function(){
	}
	Calendar.ValueController.prototype.init=function(value){
		this.element=document.createElement("div");
		this.textElement=document.createElement("span");
		this.textElement.className="value"
		this.textElement.innerHTML=this.getText();
		
		this.nextButton=document.createElement("a")
		this.nextButton.className="nextButton"
		this.nextButton.innerHTML="&gt;"
		
		this.prevButton=document.createElement("a")
		this.prevButton.className="prevButton"
		this.prevButton.innerHTML="&lt;"

		
		this.element.appendChild(this.prevButton);
		this.element.appendChild(this.textElement);
		this.element.appendChild(this.nextButton);
		
		var self=this;
		
		$(this.prevButton).bind("click",function(event){self.prevButtonClickHandle(event)})
		$(this.nextButton).bind("click",function(event){self.nextButtonClickHandle(event)})
		
		
		this.update();
	}
	Calendar.ValueController.prototype.update=function(){
		this.textElement.innerHTML=this.getText();
	}
	Calendar.ValueController.prototype.setValue=function(value){
		this.value=value;
		this.update();
	}
	Calendar.ValueController.prototype.getText=function(){
		return this.value;
	}

	Calendar.ValueController.prototype.getElement=function(){
		return this.element;
	}
	Calendar.ValueController.prototype.prevButtonClickHandle=function(event){
		this.switchValue("-");
	}
	Calendar.ValueController.prototype.nextButtonClickHandle=function(event){
		this.switchValue("+");
	}









	Calendar.MonthController=function(value,switchValue){
		this.value=value;
		this.switchValue=switchValue;
		this.init();
	}
	Calendar.MonthController.prototype=new Calendar.ValueController();
	Calendar.MonthController.prototype.getText=function(){
		var text=Calendar.MONTH_DICT[this.value]
		return text;
	}
	Calendar.MonthController.prototype.getElement=function(){
		this.element=Calendar.ValueController.prototype.getElement.call(this);
		this.element.className="month"
		return this.element;
	}

	Calendar.YearController=function(value,switchValue){
		this.value=value;
		this.switchValue=switchValue;
		this.init();
	}
	Calendar.YearController.prototype=new Calendar.ValueController();
	Calendar.YearController.prototype.getElement=function(){
		this.element=Calendar.ValueController.prototype.getElement.call(this);
		this.element.className="year"
		return this.element;
	}
	Calendar.YearController.prototype.getText=function(){
		var text=this.value+"年"
		return text;
	}
	HTMLTurbo.control.Calendar=Calendar;